<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd" >
<mapper namespace="com.rdkl.printing.dao.${cfg.moduleName}.${entity}Dao">

<!-- 通用查询结果列 -->
<sql id="Base_Column_List">
    ${table.fieldNames}
</sql>

<!-- 插入新记录 -->
<insert id="insert${entity}" parameterType="${cfg.rootPath}.dto.${entity}DTO" keyProperty="${cfg.keyFieldHump}"
        useGeneratedKeys="true">
    <selectKey resultType="java.lang.Integer" keyProperty="${cfg.keyFieldHump}" order="BEFORE">
        SELECT YW_SEQ_${cfg.keyField}.NEXTVAL FROM dual
    </selectKey>
    insert into ${table.name}
    (
        <include refid="Base_Column_List" />
    )
    values
    (
        <#list table.fields as field>
            <#noparse>#{</#noparse>${field.propertyName},jdbcType=<#if field.columnType == "DOUBLE">INTEGER<#elseif field.columnType == "LOCAL_DATE_TIME">TIMESTAMP<#elseif field.columnType == "STRING">VARCHAR<#else>${field.columnType}</#if><#noparse>}</#noparse><#if field_has_next>,</#if> <#noparse>/*</#noparse>${field.comment}<#noparse>*/</#noparse>
        </#list>
    )
</insert>

<!-- 更新 -->
<update id="update${entity}" parameterType="${cfg.rootPath}.dto.${entity}DTO">
    update ${table.name}
    set
    <#list table.fields as field>
        ${field.name}=<#noparse>#{</#noparse>${field.propertyName},jdbcType=<#if field.columnType == "DOUBLE">INTEGER<#elseif field.columnType == "LOCAL_DATE_TIME">TIMESTAMP<#elseif field.columnType == "STRING">VARCHAR<#else>${field.columnType}</#if><#noparse>}</#noparse><#if field_has_next>,</#if><#noparse>/*</#noparse>${field.comment}<#noparse>*/</#noparse>
    </#list>
    where
    ${cfg.keyField}=<#noparse>#{</#noparse>${cfg.keyFieldHump},jdbcType=INTEGER<#noparse>}</#noparse>
</update>

<!-- 按id查询 -->
<select id="get${entity}ById" parameterType="java.lang.Integer" resultType="${cfg.rootPath}.dto.${entity}DTO">
    SELECT
    <include refid="Base_Column_List" />
    FROM
    ${table.name}
    WHERE  ${cfg.keyField} = <#noparse>#{</#noparse>${cfg.keyFieldHump}<#noparse>}</#noparse>
</select>

<!-- 分页查找-->
<select id="getPage${entity}" parameterType="java.util.Map" resultType="${cfg.rootPath}.dto.${entity}DTO">
    SELECT
    <#list table.fields as field>
        ${field.name}<#if field_has_next>,</#if>
    </#list>
    FROM
        ${table.name}
    WHERE 1=1
<#noparse><!--</#noparse>
        <if test="name != null and name != ''">
            AND  yqn."NAME" like CONCAT(CONCAT('%',<#noparse>#{</#noparse>name<#noparse>})</#noparse>,'%')
        </if>
    <#noparse>--></#noparse>
    ORDER BY ${cfg.orderField} DESC
</select>

<!-- 按ids删除 -->
<delete id="delete${entity}ByIds" parameterType="java.util.Map">
    DELETE FROM ${table.name} WHERE
    ${cfg.keyField} in
    <foreach collection="list" item="${cfg.keyFieldHump}" open="(" separator="," close=")">
        <#noparse>#{</#noparse>${cfg.keyFieldHump}<#noparse>}</#noparse>
    </foreach>
</delete>



</mapper>